// DRV8833Controller.h
#ifndef DRV8833_CONTROLLER_H
#define DRV8833_CONTROLLER_H

#include <Arduino.h>

enum ROBOT_ACTION_CODE
{
    ROBOT_FORWARD = 1,
    ROBOT_BACKWARD,
    ROBOT_STOP,
    // turn
    ROBOT_TURN_LEFT,
    ROBOT_TURN_RIGHT,
    ROBOT_CENTER,
    // speed
    ROBOT_SPEED_UP,
    ROBOT_SPEED_DOWN,
};

class DRV8833Controller
{
public:
    DRV8833Controller(int forward_pin, int backward_pin, int turn_left_pin, int turn_right_pin);
    // robot running state
    enum ROBOT_ACTION_CODE state;
    enum ROBOT_ACTION_CODE cur_robot_cmd;
    // PWM - speed
    int speed;
    int turn_speed;
    int speed_step;

    void forward();
    void backward();
    void stop();
    void turn_left();
    void turn_right();
    void center();

    void speed_up();
    void speed_down();

    void action(ROBOT_ACTION_CODE robot_cmd);

private:
    int _forward_pin, _backward_pin, _turn_left_pin, _turn_right_pin; // DRV8833控制引脚
    void _running_with_new_speed();
};

#endif